package com.example.validatestudy.demos.se;

/**
 * @param
 * @version v1
 * @auther: WANGZHENFANG004
 * @summary: 内部类学习
 * @since: 2024 06 04 08 11
 */
public class ClassTest {

    private String name = "外部类类名";

    /**
     * 内部类
     */
    public class InnerClass{
        private String name = "内部类类名";
        //打印外部类的name
        public void printName(){
            System.out.println(name);
            System.out.println(ClassTest.this.name);
            System.out.println("------------");
        }
    }

    /**
     * 静态内部类
     */
    public static class StaticInnerClass{
        private String staticInnerName = "静态内部类类名";
        public void printName(){
            System.out.println(staticInnerName);
            System.out.println("------------");
        }
    }

    public void hello(){
        //无法解析
        //System.out.println(new PartInnerClass());
        /**
         * 局部内部类
         */
        class PartInnerClass{
            private String partInnerName = "局部内部类";
        }
        System.out.println(new PartInnerClass().partInnerName);
        System.out.println("------------");
    }

    public static void main(String[] args) {
        /**
         * 成员内部类、局部内部类、匿名内部类、静态内部类
         */
        //成员内部类
        InnerClass innerClass = new ClassTest().new InnerClass();
        innerClass.printName();
        //静态内部类
        new StaticInnerClass();
        StaticInnerClass staticInnerClass = new ClassTest.StaticInnerClass();
        staticInnerClass.printName();
        //局部内部类
        new ClassTest().hello();
        //匿名内部类
        Comparable<Integer> c = new Comparable<Integer>() {
            @Override
            public int compareTo(Integer o) {
                return 0;
            }
        };
        Say say = ()->{
            System.out.println("匿名内部类");
        };
        say.say();
    }

}

/**
 * 非public类，顶级类
 */
class TopClass{
    public static void main(String[] args) {
        //成员内部类、局部内部类、匿名内部类、静态内部类
        new ClassTest().new InnerClass();
        new ClassTest.StaticInnerClass();
        Comparable<Integer> c = new Comparable<Integer>() {
            @Override
            public int compareTo(Integer o) {
                return 0;
            }
        };
    }
}

/**
 * 非public接口
 */
interface Say{
    void say();
}
